<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>员工表信息操作</title>
		<link rel="stylesheet" href="./layui/css/layui.css">
	</head>
	<body>
		<div class="layui-container">
			<table id="demo"></table>
			<button id="addEmployee" class="layui-btn layui-btn-lg layui-btn-normal layui-btn-fluid">添加员工</button>
		</div>
		<!-- 引入js-->

		<script src="./layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script>
			<!-- 引入表单模块 -->
			layui.use(['layer','form','table'],function(){
				var layer = layui.layer;
				var form = layui.form;
				var table = layui.table;
				var $ = layui.jquery;

				table.render({
					id:'empChartId',
					elem:'#demo',
					// url:'getEmployee.json',
					//url:'https://localhost:44342/api/system/all-employee',
					url:'https://localhost:44342/api/system/all-employee-by-page',
					page:true,
					limit:3,
					request:{
						pageName:'pageIndex',
						limitName:'pageSize'
					},
					cols:[[
						{
							field:"empId",
							title:"员工编号",
							sort:true
						},
						{
							field:"empName",
							title:"员工姓名",
							sort:true
						},
						{
							field:"age",
							title:"年龄",
							sort:true
						},
						{
							field:"gender",
							title:"性别",
							sort:true,
							templet:function(d){
								return d.gender==1?'男':'女';
							}
						},
						{
							field:"hireDate",
							title:"入职时间",
							sort:true
						},
						{
							title:"部门名称",
							sort:true,
							templet:function(d){
								return d.department.deptName;
							}
						},
						{
							title:"操作",
							align:"center",
							templet:function(){
								//var btn1 = "<button type=\"button\" class=\"layui-btn  layui-btn-sm\">编辑</button>";
								//var btn2 = "<button type=\"button\" class=\"layui-btn  layui-btn-sm\">删除</button>";
								var btn1 = '<button type="button" class="layui-btn  layui-btn-sm">编辑</button>';
								var btn2 = '<button type="button" class="layui-btn  layui-btn-sm  layui-btn-danger">删除</button>';
								return btn1+btn2;
							}
						}
					]],
					parseData:function(d){
						console.log("d=",d);
						return {
							"code": d.statusCode==200?0:d.statusCode,
							"msg": d.succeeded,
							"count": d.data.count,
							"data": d.data.items
						}
					}
				})
				
				$("#addEmployee").click(function(){
					layer.open({
					  type: 2, 
					  title:"添加员工",
					  area:['500px','500px'],
					  end:function(){
						  table.reload('empChartId');
					  },
					  content: 'lesson8.1_AddEmployee.html' //这里content是一个普通的String
					});
				})
			});
		</script>
	</body>
</html>